home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / TEST / GLUT / keyup_test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.0 KB  |  105 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1997. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <stdio.h>
  9. #include <GL/glut.h>
  10.  
  11. void
  12. key(unsigned char key, int x, int y)
  13. {
  14.   printf("kDN: %c <%d> @ (%d,%d)\n", key, key, x, y);
  15. }
  16.  
  17. void
  18. keyup(unsigned char key, int x, int y)
  19. {
  20.   printf("kUP: %c <%d> @ (%d,%d)\n", key, key, x, y);
  21. }
  22.  
  23. void
  24. special(int key, int x, int y)
  25. {
  26.   printf("sDN: %d @ (%d,%d)\n", key, x, y);
  27. }
  28.  
  29. void
  30. specialup(int key, int x, int y)
  31. {
  32.   printf("sUP: %d @ (%d,%d)\n", key, x, y);
  33. }
  34.  
  35. void
  36. menu(int value)
  37. {
  38.   switch(value) {
  39.   case 1:
  40.     glutIgnoreKeyRepeat(1);
  41.     break;
  42.   case 2:
  43.     glutIgnoreKeyRepeat(0);
  44.     break;
  45.   case 3:
  46.     glutKeyboardFunc(NULL);
  47.     break;
  48.   case 4:
  49.     glutKeyboardFunc(key);
  50.     break;
  51.   case 5:
  52.     glutKeyboardUpFunc(NULL);
  53.     break;
  54.   case 6:
  55.     glutKeyboardUpFunc(keyup);
  56.     break;
  57.   case 7:
  58.     glutSpecialFunc(NULL);
  59.     break;
  60.   case 8:
  61.     glutSpecialFunc(special);
  62.     break;
  63.   case 9:
  64.     glutSpecialUpFunc(NULL);
  65.     break;
  66.   case 10:
  67.     glutSpecialUpFunc(specialup);
  68.     break;
  69.   }
  70. }
  71.  
  72. void
  73. display(void)
  74. {
  75.   glClear(GL_COLOR_BUFFER_BIT);
  76.   glFlush();
  77. }
  78.  
  79. int
  80. main(int argc, char **argv)
  81. {
  82.   glutInit(&argc, argv);
  83.   glutCreateWindow("keyup test");
  84.   glClearColor(0.49, 0.62, 0.75, 0.0);
  85.   glutDisplayFunc(display);
  86.   glutKeyboardFunc(key);
  87.   glutKeyboardUpFunc(keyup);
  88.   glutSpecialFunc(special);
  89.   glutSpecialUpFunc(specialup);
  90.   glutCreateMenu(menu);
  91.   glutAddMenuEntry("Ignore autorepeat", 1);
  92.   glutAddMenuEntry("Accept autorepeat", 2);
  93.   glutAddMenuEntry("Stop key", 3);
  94.   glutAddMenuEntry("Start key", 4);
  95.   glutAddMenuEntry("Stop key up", 5);
  96.   glutAddMenuEntry("Start key up", 6);
  97.   glutAddMenuEntry("Stop special", 7);
  98.   glutAddMenuEntry("Start special", 8);
  99.   glutAddMenuEntry("Stop special up", 9);
  100.   glutAddMenuEntry("Start special up", 10);
  101.   glutAttachMenu(GLUT_RIGHT_BUTTON);
  102.   glutMainLoop();
  103.   return 0;             /* ANSI C requires main to return int. */
  104. }
  105.